<?php
defined( 'BASEPATH' ) or exit( 'No direct script access allowed' );
class Setting_model extends MY_Model
{
    private $_setting = array ();
    function load($gid = null)
    {
        $this->_db->select( $this->_table, '`key`,`value`,`value_type`' );
        if (isset( $gid ))
        {
            $this->_db->where( '`gid`=?', $gid );
        }
        $configs = $this->_db->fetch_all();
        foreach ( $configs as $item )
        {
            if ($item['value_type'] == 2)
            {
                $this->_setting[$item['key']] = ( bool ) $item['value'];
            }
            elseif ($item['value_type'] == 1)
            {
                $this->_setting[$item['key']] = ( int ) $item['value'];
            }
            else
            {
                $this->_setting[$item['key']] = $item['value'];
            }
        }
        return ! empty( $this->_setting );
    }
    function get($key = null)
    {
        if ($key === null)
        {
            return $this->_setting;
        }
        return isset( $this->_setting[$key] ) ? $this->_setting[$key] : null;
    }
}